package com.the4man.cnbdw.action;

import com.opensymphony.xwork2.ModelDriven;
import com.the4man.cnbdw.service.EmployeePunchHistoryService;
import com.the4man.cnbdw.utils.Page;
import com.the4man.framework.action.BaseAction;
import com.the4man.framework.model.DataGrid;
import com.the4man.framework.model.EmployeePunchHistory;
import com.the4man.framework.model.EmployeePunchHistoryExample;
import com.the4man.framework.model.gen.EmployeePunchHistoryExampleBase;
import com.the4man.framework.util.LOG;
import com.the4man.framework.util.PageJson;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

@Action(
        value = "employeePunchHistoryAction",
        results = {@Result(
                name = "addPage",
                location = "/cnbdw/employeePunchHistory/add.jsp"
        ), @Result(
                name = "listPage",
                location = "/cnbdw/employeePunchHistory/list.jsp"
        ), @Result(
                name = "editPage",
                location = "/cnbdw/employeePunchHistory/edit.jsp"
        )}
)
public class EmployeePunchHistoryAction extends BaseAction implements ModelDriven<EmployeePunchHistory> {
    private EmployeePunchHistory employeePunchHistory = new EmployeePunchHistory();
    @Autowired
    private EmployeePunchHistoryService employeePunchHistoryService;

    public EmployeePunchHistoryAction() {
    }

    public String indexPage() {
        return "listPage";
    }

    public String toAddPage() {
        return "addPage";
    }

    public String toEditPage() {
        return "editPage";
    }

    public void getAllDatasourceList() {
        try {
            EmployeePunchHistoryExample employeePunchHistoryExample = new EmployeePunchHistoryExample();
            EmployeePunchHistoryExampleBase.Criteria cc = employeePunchHistoryExample.createCriteria();
            if(StringUtils.isNotEmpty(this.employeePunchHistory.getEmpId())) {
                cc.andEmpIdEqualTo(this.employeePunchHistory.getEmpId());
            }

            if(this.employeePunchHistory.getStart() != null) {
                cc.andCreateTimeGreaterThanOrEqualTo(this.employeePunchHistory.getStart());
            }

            if(this.employeePunchHistory.getEnd() != null) {
                cc.andCreateTimeLessThanOrEqualTo(this.employeePunchHistory.getEnd());
            }

            this.employeePunchHistoryService.countByExample(employeePunchHistoryExample);
            Page<EmployeePunchHistory> page = new Page();
            this.setPageProperties(page);
            this.employeePunchHistoryService.selectByExample(employeePunchHistoryExample, page);
            DataGrid d = new DataGrid();
            d.setRows(page.getData());
            d.setTotal(Long.valueOf((long)page.getRowCount()));
            this.writeJson(d);
        } catch (Exception var6) {
            LOG.error("获取数据失败", var6, new String[0]);
        }

    }

    public String executeModifyResult() {
        try {
            Object instance = this.employeePunchHistoryService.selectByPrimaryKey(this.employeePunchHistory.getId(), EmployeePunchHistory.class);
            this.getRequest().setAttribute("instance", instance);
        } catch (Exception var2) {
            LOG.error("获取数据失败", var2, new String[0]);
        }

        return "modifyPage";
    }

    public void delete() {
        PageJson json = new PageJson();

        try {
            int i = this.employeePunchHistoryService.deleteByPrimaryKey(this.getRequest().getParameter("ids"), EmployeePunchHistory.class);
            if(i > 0) {
                json.setReturnMsg("删除成功！");
                json.setReturnFlag(true);
            } else {
                json.setReturnMsg("删除失败！");
                json.setReturnFlag(false);
            }
        } catch (Exception var3) {
            LOG.error("批量删除失败！", var3, new String[0]);
            json.setReturnMsg("删除失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public void verify() {
        PageJson json = new PageJson();
        this.writeJson(json);
    }

    public EmployeePunchHistory getModel() {
        return this.employeePunchHistory;
    }
}
